//
//  MyViewController.swift
//  groupTasks
//
//  Created by 向银泉 on 16/11/1.
//  Copyright © 2016年 向银泉. All rights reserved.
//

import UIKit

class MyViewController: UIViewController {
    var tableView:UITableView!
    lazy var dataArray:[[(String,String)]] = {
        var tempArray = [[(String,String)]]()
        tempArray.append([("收藏","收藏"),("反馈","反馈"),("关于我们","关于我们"),("地区","地区"),("清除缓存","设置-清除缓存"),("消息推送","推送消息")])
        return tempArray
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.creatUI()
        
    }
    func creatUI(){
        self.tableView = UITableView.init(frame: self.view.bounds)
        self.tableView.backgroundColor = UIColor.whiteColor()
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.view.addSubview(self.tableView)
        self.tableView.registerNib(UINib.init(nibName: "MYheaderfooter", bundle: nil), forHeaderFooterViewReuseIdentifier: "header")
        self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }
   
}
extension MyViewController:UITableViewDelegate,UITableViewDataSource{
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return  self.dataArray.count
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArray[section].count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)
        cell.accessoryType = .DisclosureIndicator
        let data = self.dataArray[indexPath.section][indexPath.row]
        cell.imageView?.image = UIImage.init(named: data.1)
        cell.textLabel?.text = data.0
        return cell
    }
    
    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let header = self.tableView.dequeueReusableHeaderFooterViewWithIdentifier("header") as! MYheaderfooter
        header.loginInImageView?.image = UIImage.init(named: "denglu")
        header.loginButton?.setTitle("登录", forState: .Normal)
        header.separtLineView?.backgroundColor = UIColor.darkGrayColor()
        header.registerButton?.setTitle("注册", forState: .Normal)
        header.registerImageView?.image = UIImage.init(named: "111")
        header.loginButton.addTarget(self , action: #selector(MyViewController.LoginAction), forControlEvents: .TouchUpInside)
        header.registerButton.addTarget(self, action: #selector(MyViewController.registerAction), forControlEvents: .TouchUpInside)
        return header
    }
    
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 70
    }
    
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        return 80
    }
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if indexPath.section == 0{
            //收藏
            if indexPath.row == 0{
                
            }
            //反馈
            if indexPath.row == 1{
                //self.navigationController?.hidesBottomBarWhenPushed = true
                self.navigationController?.pushViewController(feedBackViewController(), animated: true)
            }
            //关于我们
            if indexPath.row == 2{
               // self.navigationController?.hidesBottomBarWhenPushed = true
                self.navigationController?.pushViewController(AboutOusViewController(), animated: true)
            }
            //地区
            if indexPath.row == 3{
               self.presentViewController(areaViewController(), animated: true, completion: { 
                self.navigationController?.hidesBottomBarWhenPushed = true
               })
            }
            //消息推送
            if indexPath.row == 5{
                
            }
        if indexPath.row == 4{
            let size = SDImageCache.sharedImageCache().getSize()
            let message = String(format: "当前有%.2fM缓存", size / (1024 * 1024))
            let alertVC = UIAlertController(title: "提示", message: message, preferredStyle: .Alert)
            let conformAction = UIAlertAction(title: "确定", style: .Default) { (action) in
                SDImageCache.sharedImageCache().clearMemory()
                SDImageCache.sharedImageCache().cleanDisk()
                SDImageCache.sharedImageCache().clearDisk()
            }
            alertVC.addAction(conformAction)
            self.presentViewController(alertVC, animated: true, completion: nil)
        }
        }
    }
    func LoginAction(){
    self.navigationController?.pushViewController(LoginViewController(), animated: true)
      
    }
    func registerAction(){
       self.navigationController?.pushViewController(registerViewController(), animated: true)
    }
    
}